package chapter01

/*
 * @ author:  changyubiao
 * * @ date: 2020/11/24 10:51
 *  条件语句
 * * @ 条件语句
 * https://www.w3cschool.cn/groovy/groovy_decision_making.html
 * if else
 * if
 * 嵌套 if
 * switch
 * 嵌套 switch

 *   switch 语句
 * https://www.w3cschool.cn/groovy/groovy_switch_statement.html
 *
 *
*/

class DecisionMaking {

    public static void main(String[] args) {

        ifElse(10, 20);
        ifElse(20, 10);
        ifElse2(40, 20);
        ifElse2(20, 40);

    }

    static void ifElse2(int a, int b) {
        if (a > b) {
            println("${a} is greater than ${b}");
        }

    }

    static void ifElse(int a, int b) {
        if (a > b) {
            println("${a} is greater than ${b}");
        } else {
//            println("a is not greater than b")
            println("${a} is not greater than ${b}");
        }
    }
}


class DecisionMaking2 {
    static void main(String[] args) {
        // Initializing a local variable
        int a = 12

        //Check for the boolean condition
        if (a < 100) {
            //If the condition is true print the following statement
            println("The value is less than 100");
        } else // Check if the value of a is greater than 5
        //  注意这里 这是 else 的子句
        if (a > 5) {
            //If the condition is true print the following statement
            println("The value is greater than 5 and less than 100");
        } else {
            //If the condition is false print the following statement
            println("The value of a is less than 5");
        }

    }
}



class DecisionMaking3 {
//    //    switch 3
    static void main(String[] args) {
        //initializing a local variable
        int a = 2

        //Evaluating the expression value
        switch(a) {
        //There is case statement defined for 4 cases
        // Each case statement section has a break condition to exit the loop
            case 1:
                println("The value of a is One");
                break;
            case 2:
                println("The value of a is Two");
                break;
            case 3:
                println("The value of a is Three");
                break;
            case 4:
                println("The value of a is Four");
                break;
            default:
                println("The value is unknown. value:${a}");
                break;
        }
    }
}


class DecisionMaking4 {
    /*
    嵌套 switch 语句
    * **/
    static void main(String[] args) {
        //Initializing 2 variables i and j
        int i = 0;
        int j = 1;

        // First evaluating the value of variable i
        switch(i) {
            case 0:
                // Next evaluating the value of variable j
                switch(j) {
                    case 0:
                        println("i is 0, j is 0");
                        break;
                    case 1:
                        println("i is 0, j is 1");
                        break;

                        // The default condition for the inner switch statement
                    default:
                        println("nested default case!! , i is ${i}, j is ${j}");
                }
                break;

                // The default condition for the outer switch statement
            default:
                println("No matching case found!!, i is ${i}, j is ${j}");
        }
    }
}
